'use strict';

const Controller = require('./base');

class MaintainController extends Controller {
  // async page() {
  //   const { ctx } = this;
  //   const query = ctx.query
  //   ctx.validate({
  //     limit: { type: 'string', required: true },
  //     page: { type: 'string', required: true },
  //   }, query);
  //   const res = await ctx.service.maintain.page(query);
  //   if (res) {
  //     this.success(res);
  //   } else {
  //     this.error('查询失败！');
  //   }
  // }
  async myMaintain() {
    const { ctx } = this
    const query = ctx.query
    ctx.validate({
      limit: { type: 'string', required: true },
      page: { type: 'string', required: true },
    }, query);
    const res = await ctx.service.maintain.myMaintain(query);
    if (res) {
      this.success(res);
    } else {
      this.error('查询失败！');
    }
  }
  async handleReceive() {
    const { ctx } = this
    const body = ctx.request.body
    const res = await ctx.service.maintain.handleReceive(body);
    if (res) {
      this.success('接单成功');
    } else {
      this.error('接单失败');
    }
  }
  async myMaintainDelete() {
    const { ctx } = this
    const body = ctx.request.body
    ctx.validate({
      num: { type: 'string', required: true },
    }, body)
    const res = await ctx.service.maintain.myMaintainDelete(body.num)
    if (res) {
      this.success('删除成功')
    } else {
      this.error('删除失败')
    }
  }
  async myMaintainUpdate() {
    const { ctx } = this
    const body = ctx.request.body
    ctx.validate({
      num: { type: 'string', required: true },
    }, body);
    const res = await ctx.service.maintain.myMaintainUpdate(body)
    if (res) {
      this.success('修改成功')
    } else {
      this.error('修改失败')
    }
  }
}

module.exports = MaintainController;
